<?php
/**
 * Created by PhpStorm.
 * User: legendnan
 * Date: 2017-10-18
 * Time: 15:58
 * QQ  : 524881622
 */
//单位分


$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);
$redis->auth('qsxcx@110');

$remainNums      = 3;
$remainMoneys    = 1*100;
while (!empty($remainNums)) {
    $money = getRandomMoney($remainNums, $remainMoneys);
    $redis->lPush('lists', $money);
}
$redis->lPop('lists');
$length = $redis->lLen('lists');

$lists = $redis->lRange('lists', 0, $length - 1);
var_dump($lists);
//$redis->del('lists');
//创建红包时生成相应方法
function getRandomMoney(&$remainNum, &$remainMoney)
{
    if ($remainNum == 1) {
        $remainNum--;
        return $remainMoney;
    }
    $randomNum = mt_rand(100000,999999);
    $seed = $randomNum / 1000000;
    $min = 1;
    $max = $remainMoney / $remainNum *2;
    $money = $seed * $max;
    if($money <= $min || $money >= $max){
        $money = $min;
    }else{
        $money = floor($money);
    }
    //TODO 如果多个红包中某个金额大于10元则通知我，并指定获得者为我
    $remainNum--;
    $remainMoney -= $money;
    return $money;
}